import request from "."
import type { PageInfo, ApiPageResult, ApiResult } from "@/lib/model"

export default {
    page(dto: ApiResourceSearch) {
        return request.getJson<ApiResourceSearch, ApiPageResult<ApiResourceItem>>("/api/resource", dto)
    },
    delete(ids: number[]) {
        return request.deleteJson<number[], ApiResult>("/api/resource", ids)
    },
    save(dto: ApiResourceItem) {
        return request.postJson<ApiResourceItem, ApiResult>("/api/resource", dto)
    },
}

export interface ApiResourceSearch extends PageInfo {
    name?: string
}

export interface ApiResourceItem {
    "id"?: number
    "enabled"?: boolean
    "name"?: string
    "displayName"?: string
    "description"?: string
    "allowedAccessTokenSigningAlgorithms"?: string
    "showInDiscoveryDocument"?: boolean
    "secrets"?: {
        "id"?: number
        "description"?: string
        "value"?: string
        "expiration"?: string
        "type"?: string
        "created"?: string
        "apiResourceId"?: number
    }[]
    "scopes"?: {
        "id"?: number
        "scope"?: string
        "apiResourceId"?: number
    }[]
    "userClaims"?: {
        "id"?: number
        "type"?: string
        "apiResourceId"?: number
    }[]
    "properties"?: {
        "id"?: number
        "key"?: string
        "value"?: string
        "apiResourceId"?: number
    }[]
    "created"?: string
    "updated"?: string
    "lastAccessed"?: string
    "nonEditable"?: boolean
}

